
// var CryptoJS = require("crypto-js");

const orgKey = '1234567890123456'
const KEY = CryptoJS.enc.Utf8.parse(orgKey)
const IV = CryptoJS.enc.Utf8.parse(orgKey)
//加密
const encrypt = async (word) => {
    let key = KEY
	let iv = IV
	let srcs = CryptoJS.enc.Utf8.parse(word);
	let encrypted = CryptoJS.AES.encrypt(srcs, key, {
		iv: iv,
		mode: CryptoJS.mode.CBC,
		padding: CryptoJS.pad.Pkcs7
	});
	return encrypted.ciphertext.toString().toUpperCase();
}



//解密
const decrypt = async (word) => {
    let key = KEY
	let iv = IV
	let encryptedHexStr = CryptoJS.enc.Hex.parse(word);
	let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
	let decrypt = CryptoJS.AES.decrypt(srcs, key, {
		iv: iv,
		mode: CryptoJS.mode.CBC,
		padding: CryptoJS.pad.Pkcs7
	});
	let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
	return decryptedStr.toString();
}



module.exports = {
    encrypt,
    decrypt
};